<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\widgets\DatePicker;
use kartik\file\FileInput;
use common\models\business\BusinessVariety;
use yii\helpers\ArrayHelper;
use yii\web\JsExpression;
/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessPig */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
        <div class="panel-body">
            <div class="adv-table editable-table ">
                <div class="business-pig-form">
                    <?php $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],
                        'fieldConfig' => [
                            'template' => "<div class='col-xs-3 col-sm-2 text-right'>{label}</div><div class='col-xs-9 col-sm-7'>{input}</div><div class='col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0'>{error}</div>",
                        ]
                    ]); ?>


                    <?= $form->field($model, 'no')->textInput(['maxlength' => true]) ?>

                    <?= $form->field($model, 'unino')->textInput(['maxlength' => true]) ?>

<!--                    <div class="form-group required has-success">-->
<!--                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-no">编号</label></div>-->
<!--                        <div class="col-md-1 col-lg-2">-->
<!--                            <input type="text" name="BusinessPig[no]" id="businesspig-no" class="form-control" value="--><?//=$model['no']?><!--" maxlength="255" aria-invalid="false" aria-required="true" />-->
<!--                        </div>-->
<!--                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-unino">国家畜牧统一编码</label></div>-->
<!--                        <div class="col-md-1 col-lg-2">-->
<!--                            <input type="text" name="BusinessPig[unino]" id="businesspig-unino" class="form-control" value="--><?//=$model['unino']?><!--" maxlength="255" aria-invalid="false" aria-required="true" />-->
<!--                        </div>-->
<!--                    </div>-->


                    <div class="form-group">
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-weight">体重（kg）</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[weight]" id="businesspig-weight" class="form-control" value="<?=$model['weight']?>" maxlength="255" aria-invalid="false" aria-required="true">
                        </div>
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-weight">高度（cm）</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[height]" id="businesspig-height" class="form-control" value="<?=$model['height']?>" maxlength="255" aria-invalid="false" aria-required="true">
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-length">体长（cm）</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[length]" id="businesspig-weight" class="form-control" value="<?=$model['length']?>" maxlength="255" aria-invalid="false" aria-required="true">
                        </div>
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-width">体宽（cm）</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[width]" id="businesspig-width" class="form-control" value="<?=$model['width']?>" maxlength="255" aria-invalid="false" >
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-activelevel">精神</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[activelevel]" id="businesspig-activelevel" class="form-control" value="<?=$model['activelevel']?>" maxlength="255" aria-invalid="false">
                        </div>
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-haircolor">毛色</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[haircolor]" id="businesspig-haircolor" class="form-control" value="<?=$model['haircolor']?>" maxlength="255" aria-invalid="false">
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-foodintake">食量</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[foodintake]" id="businesspig-foodintake" class="form-control" value="<?=$model['foodintake']?>" maxlength="255" aria-invalid="false">
                        </div>
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-shit">大便</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[shit]" id="businesspig-shit" class="form-control" value="<?=$model['shit']?>" maxlength="255" aria-invalid="false">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-breath">呼吸情况</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[breath]" id="businesspig-breath" class="form-control" value="<?=$model['breath']?>" maxlength="255" aria-invalid="false">
                        </div>
                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-temperature">体温</label></div>
                        <div class="col-md-1 col-lg-2">
                            <input type="text" name="BusinessPig[temperature]" id="businesspig-temperature" class="form-control" value="<?=$model['temperature']?>" maxlength="255" aria-invalid="false">
                        </div>
                    </div>



<!---->
<!--                    <div class="form-group required has-success">-->
<!--                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-batch">批次</label></div>-->
<!--                        <div class="col-md-1 col-lg-2">-->
<!--                            <input type="text" name="BusinessPig[batch]" id="businesspig-batch" class="form-control" value="--><?//=$model['batch']?><!--" maxlength="255" aria-invalid="false" aria-required="true">-->
<!--                        </div>-->
<!--                        <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesspig-price">价格</label></div>-->
<!--                        <div class="col-md-1 col-lg-2">-->
<!--                            <input type="text" name="BusinessPig[price]" id="businesspig-price" class="form-control" value="--><?//=$model['price']?><!--" maxlength="255" aria-invalid="false">-->
<!--                        </div>-->
<!--                        <div class="col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0"><div class="help-block"></div></div>-->
<!--                    </div>-->
<!---->

                    <?= $form->field($model, 'batch')->textInput(['maxlength' => true]) ?>
                    <?= $form->field($model, 'price')->textInput(['maxlength' => true]) ?>
                    <?= $form->field($model, 'ling_total_price')->textInput(['maxlength' => true]) ?>

                    <?= $form->field($model, 'cost')->textInput(['maxlength' => true]) ?>
                    <?= $form->field($model, 'varietyid')->dropDownList(ArrayHelper::map(BusinessVariety::find()->asArray()->all(),'id','title'),['style'=>'width:400px;']) ?>
                    <?= $form->field($model, 'canlivery')->dropDownList(\common\models\business\BusinessPig::$canlivery,['style'=>'width:400px;']) ?>
                    <?= $form->field($model, 'isindex')->dropDownList(\common\models\business\BusinessPig::$isindex,['style'=>'width:400px;']) ?>


                    <?= $form->field($model, 'livery')->widget(\kartik\select2\Select2::className(), [
                        'options' => ['placeholder' => '请输入农户真实姓名 ...'],
                        'initValueText'=>!$model->liveryperson?'':$model->liveryperson->name,
                        'pluginOptions' => [
                            'allowClear' => true,
                            'minimumInputLength' => 1,//重要
                            'language' => [
                                'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                            ],

                            'ajax' => [
                                'url' => '/business/search/search-farmer',
                                'dataType' => 'json',
                                'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                'cache' => true
                            ],
                            'width' => '400px',
                            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                            'templateResult' => new JsExpression('function(res) { return res.text; }'),
                            'templateSelection' => new JsExpression('function (res) { return res.text; }'),
                            'tags' => true,
                            'maximumInputLength' => 10
                        ],
                    ]);
                    ?>

                    <?= $form->field($model, 'headpersonid')->widget(\kartik\select2\Select2::className(), [
                        'options' => ['placeholder' => '请输入业务员姓名 ...'],
                        'initValueText'=>$model->headperson,
                        'pluginOptions' => [
                            'allowClear' => true,
                            'minimumInputLength' => 1,//重要
                            'language' => [
                                'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                            ],
                            'ajax' => [
                                'url' => '/business/search/search-person',
                                'dataType' => 'json',
                                'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                'cache' => true
                            ],
                            'width' => '400px',
                            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                            'templateResult' => new JsExpression('function(res) { return res.text; }'),
                            'templateSelection' => new JsExpression('function (res) { return res.text; }'),
                        ],
                    ]);
                    ?>



                    <?= $form->field($model, 'fileid')->widget(\kartik\select2\Select2::className(), [
                        'options' => ['placeholder' => '请输入档案名称或者编号 ...'],
                        'initValueText'=>!$model->file?'':$model->file->name,
                        'pluginOptions' => [
                            'allowClear' => true,
                            'minimumInputLength' => 1,//重要
                            'language' => [
                                'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                            ],
                            'ajax' => [
                                'url' => '/business/search/search-file',
                                'dataType' => 'json',
                                'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                'cache' => true
                            ],
                            'width' => '400px',
                            'escapeMarkup' => new JsExpression('function (markup) { return markup;}'),
                            'templateResult' => new JsExpression('function(res) { return res.text;}'),
                            'templateSelection' => new JsExpression('function (res) { return res.text;}'),
                        ],
                    ]);
                    ?>
                    <?= $form->field($model, 'lingperson')->widget(\kartik\select2\Select2::className(), [
                        'options' => ['placeholder' => '请输入领养人昵称...'],
                        'initValueText'=>!$model->linger?'':$model->linger->nickname,
                        'pluginOptions' => [
                            'disabled' => true,
                            'allowClear' => true,
                            'minimumInputLength' => 1,//重要
                            'language' => [
                                'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                            ],
                            'ajax' => [
                                'url' => '/business/search/search-user',
                                'dataType' => 'json',
                                'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                'cache' => true
                            ],
                            'width' => '400px',
                            'escapeMarkup' => new JsExpression('function (markup) { return markup;}'),
                            'templateResult' => new JsExpression('function(res) { return res.text;}'),
                            'templateSelection' => new JsExpression('function (res) { return res.text;}'),
                        ],
                    ]);
                    ?>

                    <?php
//                    $form->field($model, 'beforevaccinetime')->widget(DatePicker::classname(), [
//                        'options' => ['placeholder' => '入栏前疫苗时间'],
//                        'pluginOptions' => [
//                            'autoclose'=>true,
//                            'format' => 'yyyy-mm-dd'
//                        ]
//                    ]);
                    ?>

                    <?php
//                    $form->field($model, 'aftervaccinetime')->widget(DatePicker::classname(), [
//                        'options' => ['placeholder' => '入栏后疫苗时间'],
//                        'pluginOptions' => [
//                            'autoclose'=>true,
//                            'format' => 'yyyy-mm-dd'
//                        ]
//                    ]);
                    ?>

                    <?=
                    $form->field($model, 'intime')->widget(DatePicker::classname(), [
                        'options' => ['placeholder' => '入栏时间'],
                        'pluginOptions' => [
                            'autoclose'=>true,
                            'format' => 'yyyy-mm-dd'
                        ]
                    ]);
                    ?>
                    <?=
                    $form->field($model, 'planout')->widget(DatePicker::classname(), [
                        'options' => ['placeholder' => '预计出栏时间'],
                        'pluginOptions' => [
                            'autoclose'=>true,
                            'format' => 'yyyy-mm-dd'
                        ]
                    ]);
                    ?>




                    <?= $form->field($model, 'status')->dropDownList(\common\models\business\BusinessPig::$statues) ?>

                    <?= $form->field($model, 'gender')->dropDownList([''=>'','公'=>'公','母'=>'母']) ?>


                    <?= $form->field($model, 'photo[]')->widget(FileInput::classname(), [
                        'options' => ['multiple' => true],
                        'pluginOptions' => [
                            // 需要预览的文件格式
                            'previewFileType' => 'image',
                            // 预览的文件
                            'initialPreview' => \common\components\Upload::checkGetUrl($model->photo,true,'photo'),
                            // 需要展示的图片设置，比如图片的宽度等
                            'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'photo',\common\models\business\BusinessPig::tableName(),$model->id),
                            // 是否展示预览图
                            'initialPreviewAsData' => true,
                            'overwriteInitial' => false,
                            'showUpload' => false,
                        ],
                    ]); ?>

                    <?= $form->field($model, 'screen_photo[]')->widget(FileInput::classname(), [
                        'options' => ['multiple' => true],
                        'pluginOptions' => [
                            // 需要预览的文件格式
                            'previewFileType' => 'image',
                            // 预览的文件
                            'initialPreview' => \common\components\Upload::checkGetUrl($model->screen_photo,true,'screen_photo'),
                            // 需要展示的图片设置，比如图片的宽度等
                            'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'screen_photo',\common\models\business\BusinessPig::tableName(),$model->id),
                            // 是否展示预览图
                            'initialPreviewAsData' => true,
                            'overwriteInitial' => false,
                            'showUpload' => false,
                        ],
                    ]); ?>

                    <?= $form->field($model, 'video[]')->widget(FileInput::classname(), [
                        'options' => ['multiple' => true],
                        'pluginOptions' => [
                            // 需要预览的文件格式
                            'previewFileType' => 'video',
                            // 预览的文件
                            'initialPreview' => \common\components\Upload::checkGetUrl($model->video,true,'video'),
                            // 需要展示的图片设置，比如图片的宽度等
                            'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'video',\common\models\business\BusinessPig::tableName(),$model->id,'id','video'),
                            // 是否展示预览图
                            'initialPreviewAsData' => true,
                            'showUpload' => false,
                            'overwriteInitial' => false,
                            'maxFileSize' => 100000,
                        ],
                    ]); ?>

                    <?= $form->field($model, 'liveryremark')->textarea(['maxlength' => true]) ?>

                    <?= $form->field($model,'slaughter')->widget('kucha\ueditor\UEditor',[
                        'clientOptions' => [
                            //编辑区域大小
                            'initialFrameHeight' => '350',
                            //设置语言
                            'lang' =>'zh-cn', //中文为 zh-cn
                            //定制菜单
                            'toolbars' => [
                                [
                                    'fullscreen', 'source', 'undo', 'redo', '|','fontsize','link','spechars','searchreplace','lineheight','charts',
                                    'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat',
                                    'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|',
                                    'forecolor', 'backcolor', '|',
                                    'lineheight', '|','emotion',
                                    'indent', '|',
                                    'snapscreen','insertimage','imagecenter','wordimage'
                                ],
                            ]
                        ]
                    ]); ?>




                    <div class="form-group">
                        <?= Html::submitButton($model->isNewRecord ? '确认提交' : '确认更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
                    </div>
                    <?php ActiveForm::end(); ?>
                </div>
            </div>
        </div>
    </section>
</div>
</div>